import { md5 } from 'js-md5'
import { postService, postServiceList } from '.'
import { PORT1 } from '../config/net.config'
import { User } from './interface/user'
import { loginRSA } from '/@/config'
import request from '/@/utils/request'

interface FormType {
  password: string
  password2?: string
  phone: string
  phoneCode: string
  username: string
  verificationCode: string
}

export const login = async (data: any) => {
  if (loginRSA) data = { ...data, password: md5(data.password) }
  return request({
    url: `${PORT1}/Login/GetJwtToken`,
    method: 'post',
    data,
  })
}
export const getIdentify = async (data: any) => {
  return request({
    url: `${PORT1}/Login/GetIdentify`,
    method: 'post',
    data,
    headers: {
      // 'Content-Type': 'multipart/form-data',
    },
  })
}
export const getNavs = async (data: any) => {
  return postService(`${PORT1}/SysMenuPage/GetPageList`, data, 'form')
}
export const getButtons = async (data: any) => {
  return request({
    url: `${PORT1}/SysMenuPageDict/GetPageList`,
    method: 'post',
    data,
  })
}

export const getUserInfo = (params: {}) => {
  return postService<User.UserInfo>(`${PORT1}/Tools/GetEditUserInfo`, params, 'json')
}

export const editUserInfoAPI = (params: User.UserInfo) => {
  return postService<null>(`${PORT1}/Tools/EditLoginUserInfo`, params, 'json')
}
export const changePasswordAPI = (params: User.ChangePriceForm) => {
  return postService<null>(`${PORT1}/SysUser/ChangePassWord`, params, 'form')
}
// 前台角色
export const getRoleFrontAPI = (params: {}) => {
  return postServiceList<User.RoleFront>(`${PORT1}/sysrolepos/getpageList`, params, false)
}
export const editRoleFrontAPI = (params: User.RoleFront) => {
  return postService<null>(`${PORT1}/sysrolepos/doedit`, params, 'json')
}
export const createRoleFrontAPI = (params: User.RoleFront) => {
  return postService<null>(`${PORT1}/sysrolepos/docreate`, params, 'json')
}
export const deleteRoleFrontAPI = (params: { id: number[] }) => {
  return postService<null>(`${PORT1}/sysrolepos/DoBatchDelete`, params, 'json')
}

// 后台角色
export const getRoleBackAPI = (params: {}) => {
  return postServiceList<User.RoleBack>(`${PORT1}/SysRole/GetPageList`, params, false)
}
export const createRoleBackAPI = (params: {}) => {
  return postService<null>(`${PORT1}/SysRole/DoCreate`, params, 'json')
}
export const editRoleBackAPI = (params: {}) => {
  return postService<null>(`${PORT1}/SysRole/DoEdit`, params, 'json')
}
export const deleteRoleBackAPI = (params: { id: number[] }) => {
  return postService<null>(`${PORT1}/SysRole/DoBatchDelete`, params, 'json')
}

// / 收银管理
export const getRoleAuthorityAPI = (params: { id: number | string }) => {
  return postService<User.RoleAuthority>(`${PORT1}/SysRole/GetSysRolePos`, params)
}
// / 收银管理
export const setRoleAuthorityAPI = (params: User.RoleAuthority) => {
  return postService<null>(`${PORT1}/SysRole/SetSysRolePos`, params)
}

// 获取角色权限列表
export const getLoadMenuPageDictListAPI = (params: { id: number | string }) => {
  return postService<User.LoadMenuPageDict[]>(`${PORT1}/SysMenuPagEdict/LoadMenuPageDictList`, params)
}
// 配置角色权限列表
export const setLoadMenuPageDictListAPI = (params: { id: number | string; data: User.LoadMenuPageDict }) => {
  return postService<null>(`${PORT1}/SysMenuPageDict/SetMenuPageDict`, params)
}

// 用户管理列表
export const getUserMangerAPI = (params: {}) => {
  return postServiceList<User.ResUserList>(`${PORT1}/SysUser/GetPageList`, params, false)
}
// 删除用户管理
export const deleteUserMangerAPI = (params: { id: number | string }) => {
  return postService<null>(`${PORT1}/SysUser/DoDelete`, params)
}
// 新增用户管理
export const createUserMangerAPI = (params: {}) => {
  return postService<null>(`${PORT1}/SysUser/DoCreate`, params)
}
// 编辑用户管理
export const editUserMangerAPI = (params: {}) => {
  return postService<null>(`${PORT1}/SysUser/DoEdit`, params)
}
// 重置密码
export const resetPasswordAPI = (params: { id: number | string }) => {
  return postService<null>(`${PORT1}/SysUser/ResetPassword`, params)
}
